$(document).ready(function () {
    var company = [{
            date: "1985",
            name: "北京北天堂残渣填埋场",
            address: "北京市丰台区北天堂村",
            division: "北京-丰台",
            center: [116.268084, 39.798441]
        }, {
            date: "1989",
            name: "北京阿苏卫垃圾卫生填埋场",
            address: "北京市昌平区北六环六环国际艺术区西北",
            division: "北京-昌平",
            center: [116.357326, 40.163015]
        }, {
            date: "1994",
            name: "北京大屯垃圾转运站",
            address: "北京市朝阳区北辰东路5号-北门",
            division: "北京-朝阳",
            center: [116.421841, 40.006898]
        }, {
            date: "1997",
            name: "北京小武基垃圾转运站",
            address: "北京市朝阳区小武基路147号",
            division: "北京-朝阳",
            center: [116.484902, 39.859762]
        }, {
            date: "1997",
            name: "北京南宫垃圾菌肥厂",
            address: "北京市大兴区瀛海京福路与兴亦路交叉路口往南500米",
            division: "北京-大兴",
            center: [116.460443, 39.73787]
        }, {
            date: "1998",
            name: "北京顺义区生活垃圾综合处理厂",
            address: "北京市顺义杨镇西庞村南",
            division: "北京-顺义",
            center: [116.875649, 40.129521]
        }, {
            date: "1998",
            name: "北京马家楼垃圾转运站",
            address: "北京市丰台区花乡马家楼桥东侧",
            division: "北京-丰台",
            center: [116.350867, 39.834496]
        }, {
            date: "1999",
            name: "北京海淀区六里屯垃圾填埋场",
            address: "北京市海淀区西北旺镇屯佃村",
            division: "北京-海淀",
            center: [116.227161, 40.059753]
        }, {
            date: "1999",
            name: "北京五路居垃圾转运站",
            address: "北京市彰化路郑王坟甲37号",
            division: "北京-海淀",
            center: [116.277834, 39.941005]
        }, {
            date: "2002",
            name: "北京朝阳循环经济产业园",
            address: "北京市朝阳区金盏乡南部",
            division: "北京-朝阳",
            center: [116.619937, 39.939137]
        }, {
            date: "2002",
            name: "北京朝阳高安屯垃圾填埋厂",
            address: "北京市朝阳区金盏乡南部",
            division: "北京-朝阳",
            center: [116.620483, 39.938704]
        }, {
            date: "2003",
            name: "北京衙门口垃圾转运站",
            address: "北京市石景山区杨庄东路65号",
            division: "北京-石景山",
            center: [116.201117, 39.88873]
        }, {
            date: "2004",
            name: "北京怀柔区垃圾综合处理产业园（沃绿洁垃圾综合处理厂）",
            address: "北京市怀柔区庙城镇孙史山村北侧",
            division: "北京-怀柔",
            center: [116.596022, 40.284043]
        }, {
            date: "2004",
            name: "北京延庆垃圾总处理厂",
            address: "北京市延庆区大小路",
            division: "北京-延庆",
            center: [116.018192, 40.402545]
        }, {
            date: "2004",
            name: "北京通州区垃圾转运站",
            address: "北京市通州区临河里小街部队南门环卫服务中心院内",
            division: "北京-通州",
            center: [116.647022, 39.851471]
        }, {
            date: "2005",
            name: "北京小张家口垃圾卫生填埋场",
            address: "北京市延庆区大榆树镇",
            division: "北京-延庆",
            center: [116.023029, 40.433578]
        }, {
            date: "2005",
            name: "北京永宁垃圾卫生填埋场",
            address: "北京市延庆区永宁镇",
            division: "北京-延庆",
            center: [116.205475, 40.541899]
        },
        {
            date: "2006",
            name: "北京高安屯医疗垃圾处理厂",
            address: "北京市朝阳区高安屯",
            division: "北京-朝阳",
            center: [116.620483, 39.938704]
        },
        {
            date: "2006",
            name: "北京董村垃圾综合处理厂",
            address: "北京通州台湖镇董村",
            division: "北京-通州",
            center: [116.544263, 39.831739]
        },
        {
            date: "2006",
            name: "北京顺政环保科技有限公司（顺义区餐厨垃圾处理厂）",
            address: "北京市顺义杨镇西庞村南",
            division: "北京-顺义",
            center: [116.875568, 40.128262]
        },
        {
            date: "2007",
            name: "北京丰台区循环经济产业园残渣填埋场",
            address: "北京市丰台区北天堂村420号",
            division: "北京-丰台",
            center: [116.270203, 39.802368]
        },
        {
            date: "2007",
            name: "北京南宫餐厨垃圾处理厂",
            address: "北京市大兴区赢海乡",
            division: "北京-大兴",
            center: [116.461366, 39.735829]
        },
        {
            date: "2007",
            name: "北京怀柔卫生填埋场",
            address: "北京市怀柔区庙城镇孙史山村北侧",
            division: "北京-怀柔",
            center: [116.599537, 40.28761]
        },
        {
            date: "2009",
            name: "北京高安屯垃圾焚烧有限公司",
            address: "北京市朝阳区高安屯北街2号院502号楼",
            division: "北京-朝阳",
            center: [116.617992, 39.94851]
        },
        {
            date: "2010",
            name: "北京东南召垃圾卫生填埋场",
            address: "北京市房山区琉璃河镇东南召村",
            division: "北京-房山",
            center: [116.126463, 39.615414]
        },
        {
            date: "2010",
            name: "北京高安屯餐厨垃圾处理厂（厨废弃物资源化处理中心）",
            address: "北京市朝阳区高安屯",
            division: "北京-朝阳",
            center: [116.623964, 39.948785]
        },
        {
            date: "2011",
            name: "北京燕山垃圾综合处理厂",
            address: "北京市燕山垃圾综合处理厂",
            division: "北京-房山",
            center: [115.949492, 39.75857]
        },
        {
            date: "2013",
            name: "北京海淀大工村循环经济产业园",
            address: "北京市海淀区苏家坨镇大工村发电厂",
            division: "北京-海淀",
            center: [116.092151, 40.040538]
        },
        {
            date: "2013",
            name: "北京顺义有机废弃物处理厂",
            address: "北京市顺义区杨镇庞山村",
            division: "北京-顺义",
            center: [116.875568, 40.128262]
        },
        {
            date: "2013",
            name: "北京密云垃圾综合处理中心",
            address: "北京市密云区巨各庄镇水峪沟",
            division: "北京-密云",
            center: [116.950598, 40.362111]
        },
        {
            date: "2013",
            name: "北京石景山生化处理厂",
            address: "北京市石景山区石景山路23号",
            division: "北京-石景山",
            center: [116.212684, 39.909521]
        },
        {
            date: "2014",
            name: "北京丰台区循环经济产业园预处理筛分厂",
            address: "北京市丰台区北天堂村420号",
            division: "北京-丰台",
            center: [116.268431, 39.803383]
        },
        {
            date: "2014",
            name: "北京丰台餐厨厨余垃圾处理厂",
            address: "北京市丰台区北天堂村420号",
            division: "北京-丰台",
            center: [116.269649, 39.802536]
        },
        {
            date: "2014",
            name: "北京丰台湿解厂",
            address: "北京市丰台区北天堂村420号",
            division: "北京-丰台",
            center: [116.269649, 39.802434]
        },
        {
            date: "2014",
            name: "北京沙河餐厨垃圾处理厂",
            address: "北京昌平区沙河镇",
            division: "北京-昌平",
            center: [116.28622, 40.18556]
        },
        {
            date: "2015",
            name: "北京大工村餐厨垃圾处理厂",
            address: "北京市海淀区苏家坨镇大工村发电厂",
            division: "北京-海淀",
            center: [116.102072, 40.043968]
        },
        {
            date: "2015",
            name: "北京首钢生物质能源科技有限公司（鲁家山垃圾焚烧发电厂）",
            address: "北京市门头沟区潭柘寺镇鲁家山首钢鲁矿南区",
            division: "北京-门头沟",
            center: [116.048033, 39.850862]
        },
        {
            date: "2015",
            name: "北京顺义生活垃圾焚烧处理一期",
            address: "北京市顺义杨镇西庞村南生活垃圾综合处理厂",
            division: "北京-顺义",
            center: [116.875649, 40.129521]
        },
        {
            date: "2015",
            name: "北京市朝阳生活垃圾综合处理厂生物处理中心试验项目",
            address: "北京市朝阳区高安屯",
            division: "北京-朝阳",
            center: [116.623964, 39.948785]
        },
        {
            date: "2015",
            name: "北京海淀大工村餐厨厨余垃圾处理厂",
            address: "北京市海淀区苏家坨镇大工村发电厂",
            division: "北京-海淀",
            center: [116.102072, 40.043968]
        },
        {
            date: "2016",
            name: "北京延庆县餐厨垃圾处理厂",
            address: "北京市延庆区大小路",
            division: "北京-延庆",
            center: [116.027873, 40.420533]
        },
        {
            date: "2016",
            name: "北京朝京环保能源科技股份有限公司（垃圾焚烧二期）",
            address: "北京市朝阳区金盏乡高安屯（北京市朝阳区循环经济产业园内）",
            division: "北京-朝阳",
            center: [116.616054, 39.948752]
        },
        {
            date: "2016",
            name: "北京顺义生活垃圾焚烧处理二期",
            address: "北京市顺义杨镇西庞村南",
            division: "北京-顺义",
            center: [116.875649, 40.129521]
        },
        {
            date: "2017",
            name: "北京丰台区循环经济产业园填埋气净化提纯厂",
            address: "北京市丰台区北天堂村420号",
            division: "北京-丰台",
            center: [116.268431, 39.803383]
        },
        {
            date: "2017",
            name: "北京北控绿海能环保有限公司（海淀苏家坨焚烧厂）",
            address: "北京市海淀区苏家坨镇大工村发电厂",
            division: "北京-海淀",
            center: [116.092151, 40.040538]
        },
        {
            date: "2017",
            name: "北京南宫生物质能源有限公司（南宫垃圾焚烧发电厂）",
            address: "北京市大兴区青云店镇南大红门村",
            division: "北京-大兴",
            center: [116.464861, 39.735862]
        },
        {
            date: "2017",
            name: "北京北控雁栖再生能源科技有限公司（怀柔区生活垃圾焚烧发电厂）",
            address: "北京市怀柔区庙城镇孙史山村北侧",
            division: "北京-怀柔",
            center: [116.595974, 40.28276]
        },
        {
            date: "2018",
            name: "北京首钢餐厨垃圾处理厂",
            address: "北京市门头沟区潭柘寺镇鲁家滩村鲁家山国家循环经济静脉产业园",
            division: "北京-门头沟",
            center: [116.461366, 39.735829]
        },
        {
            date: "2018",
            name: "北京通州再生能源发电厂",
            address: "北京市通州区永乐店镇德仁务中街村521号",
            division: "北京-通州",
            center: [116.786021, 39.66961]
        },
        {
            date: "2018",
            name: "北京首钢生态科技有限公司",
            address: "北京市门头沟区潭柘寺镇鲁家滩村南(原首钢鲁家山石灰石矿)15幢",
            division: "北京-门头沟",
            center: [116.042623, 39.851202]
        },
        {
            date: "2018",
            name: "北京京环绿谷环境管理有限公司（平谷区生活垃圾综合处理厂）",
            address: "北京市平谷区东高村镇南宅村西南500米",
            division: "北京-平谷",
            center: [117.050776, 40.063426]
        },
        {
            date: "2018",
            name: "北京绿色动力再生能源有限公司（密云垃圾焚烧厂）",
            address: "北京市密云区巨各庄镇政府208室-27",
            division: "北京-密云",
            center: [116.949952, 40.36298]
        },
        {
            date: "2018",
            name: "北京市密云区绿色循环经济产业园",
            address: "北京市密云区S204(密三路)",
            division: "北京-密云",
            center: [116.268431, 39.803383]
        },
        {
            date: "2018",
            name: "丰台区循环经济产业园渗沥液处理厂",
            address: "北京市丰台区北天堂村420号",
            division: "北京-丰台",
            center: [116.269649, 39.802434]
        },
        {
            date: "2019",
            name: "北京通州区粪便和餐厨垃圾处理厂（通州有机质资源垃圾生态处理站）",
            address: "北京市通州区潞西路",
            division: "北京-丰台",
            center: [116.607672, 39.825322]
        },
        {
            date: "2019",
            name: "北京华源惠众环保科技有限公司（阿苏卫生活垃圾焚烧发电厂）",
            address: "北京市昌平区小汤山镇阿苏卫生活垃圾焚烧发电厂",
            division: "北京-昌平",
            center: [116.349603, 40.161302]
        },
        {
            date: "2021",
            name: "北京丰台区循环经济产业园渗沥液处理厂二期",
            address: "北京市卢沟桥北天堂村420号",
            division: "北京-丰台",
            center: [116.269649, 39.802434]
        },
        {
            date: "1996",
            name: "北京安定填埋场",
            address: "北京市大兴县安定境内",
            division: "北京-大兴",
            center: [116.499778, 39.618307]
        },
        {
            date: "1997",
            name: "北京北神树垃圾卫生填埋场",
            address: "北京市科创东三街28号",
            division: "北京-通州",
            center: [116.542655, 39.814872]
        }

    ]


    var yearnum = {
        "1985": 1,
        "1986": 1,
        "1987": 1,
        "1988": 1,
        "1989": 2,
        "1990": 2,
        "1991": 2,
        "1992": 2,
        "1993": 2,
        "1994": 3,
        "1995": 3,
        "1996": 3,
        "1997": 5,
        "1998": 7,
        "1999": 9,
        "2000": 9,
        "2001": 9,
        "2002": 11,
        "2003": 12,
        "2004": 15,
        "2005": 17,
        "2006": 19,
        "2007": 23,
        "2008": 23,
        "2009": 24,
        "2010": 26,
        "2011": 27,
        "2012": 27,
        "2013": 31,
        "2014": 35,
        "2015": 40,
        "2016": 43,
        "2017": 47,
        "2018": 54,
        "2019": 56,
        "2020": 56,
        "2021": 57,

    }

    function showyear(year) {
        if (year in yearnum) {
            var num = yearnum[year];
            var deletenum = company.length - num;
            console.log(num);
            console.log(deletenum);
            for (var i = 0; i <= num - 1; i++) {
                markers[i].setMap(map);
                marker.setAnimation('AMAP_ANIMATION_DROP');
            }
            for (var i = num; i <= company.length - 1; i++) {
                markers[i].setMap(null);
            }
        }

    }

    function markerClick(e) {
        infoWindow.setContent(e.target.extData);
        infoWindow.open(map, e.target.getPosition());
    }

    var map = new AMap.Map('factorymap', {
        resizeEnable: true, //
        zoom: 8, //初始化地图层级
        //         zoomEnable: false,
        //         doubleClickZoom: false,
        //         scrollWheel: false,
        //         touchZoom: false,
        //         dragEnable: false,
        center: [116.40714, 40.19759], //初始化地图中心点
        mapStyle: "amap://styles/darkblue"
    });
    map.on('zoomchange', function () {
        var zoom = map.getZoom();
        if (zoom < 8) {
            console.log("little");
            map.setZoomAndCenter(8, [116.40714, 40.19759])
        }


    });
    var markers = [];
    var infoWindow = new AMap.InfoWindow();

    for (var i = 0; i < company.length; i += 1) {
        var center = company[i].center;
        var marker = new AMap.Marker({
            position: center,
            icon: 'images/position.png',
            map: map
        })
        markers.push(marker);
        marker.extData = company[i].name + "<br>地址：" + company[i].address + "<br>投产时间：" + company[i].date;
        marker.on('click', markerClick);
    }
    showyear("1985");
    $("#year_range").on("input", function () {
        $("#currentyear").html(this.value);
        showyear(this.value);
    })

});